package org.learn.file;

import org.junit.Test;

import java.io.File;
import java.io.IOException;

public class FileCreate {
    public static void main(String[] args) {

    }
    @Test
    //1
    public void creat01() {
        String filePath = "D:\\test\\news1.txt";
        File file = new File(filePath);

        try {
            file.createNewFile();
            System.out.println("文件创建成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //2
    public void creat02(){
        File file = new File("d:\\test");
        String fileName = "news1.txt";
        File file1 = new File(file, fileName);
        try {
            file1.createNewFile();
            System.out.println("没有异常发生");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //3
    public void creat03(){
        String parentPath = "d:\\test";
        String fileName = "news1.txt";
        File file = new File(parentPath, fileName);

        try {
            file.createNewFile();
            System.out.println("没有异常发生");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
